package com.ucode.model.hrm.convert;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import com.ucode.model.hrm.*;
import com.ucode.model.hrm.enums.HrmSocialSecurityCoverageTypeEnum;
import com.ucode.model.hrm.vo.HrmEmployeeCostDetailVO;
import com.ucode.tool.base.Paginator;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface HrmEmployeeCostDetailConvert {

    HrmEmployeeCostDetailConvert INSTANCE = Mappers.getMapper(HrmEmployeeCostDetailConvert.class);

    Paginator<HrmEmployeeCostDetailVO> convertPage(Paginator<HrmEmployeeCostDetail> page);

    List<HrmEmployeeCostDetailVO> convertList(List<HrmEmployeeCostDetail> list);

    HrmEmployeeCostDetailVO convert(HrmEmployeeCostDetail bean);
    default HrmEmployeeCostDetail convert(HrmEmployeeCompensation compensation, HrmSocialSecurityRule socialSecurityRule) {
        HrmEmployeeCostDetail detail = new HrmEmployeeCostDetail();
        detail.setHousingFundBase(compensation.getHousingFundBase());
        detail.setUnitHousingFundRate(compensation.getHousingFundEnterpriseRate());
        detail.setIndividualHousingFundRate(compensation.getHousingFundPersonalRate());
        detail.setBaseSalary(compensation.getBaseSalary());
        detail.setPositionSalary(compensation.getPerformancePay());
        //detail.setRegionalDifference(compensation.getRegionalDifference()); //地区差异津贴
        detail.setTrafficSubsidy(compensation.getTrafficAllowance());//交通补贴
        detail.setCommunicationSubsidy(compensation.getPhoneAllowance());//通讯补贴

        if(CollUtil.isNotEmpty(socialSecurityRule.getItems())) {
            for (HrmSocialSecurityRuleItem item : socialSecurityRule.getItems()){
                if(ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP1.getCode())){
                    //养老
                    detail.setPensionBase(item.getBaseAmount());
                    detail.setPensionUnitRatio(new BigDecimal(item.getCompanyRate()));
                    detail.setPensionIndividualRatio(new BigDecimal(item.getPersonalRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP2.getCode())){
                    //医疗
                    detail.setMedicalBase(item.getBaseAmount());
                    detail.setMedicalUnitRatio(new BigDecimal(item.getCompanyRate()));
                    detail.setMedicalIndividualRatio(new BigDecimal(item.getPersonalRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP3.getCode())){
                    //失业
                    detail.setUnemploymentBase(item.getBaseAmount());
                    detail.setUnemploymentUnitRatio(new BigDecimal(item.getCompanyRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP4.getCode())){
                    //工伤
                    detail.setInjuryBase(item.getBaseAmount());
                    detail.setInjuryUnitRatio(new BigDecimal(item.getCompanyRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP5.getCode())){
                    //生育
                    detail.setMaternityBase(item.getBaseAmount());
                    detail.setMaternityUnitRatio(new BigDecimal(item.getCompanyRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP6.getCode())){
                    //大病医疗
                    detail.setUnitSeriousMedicalBase(item.getBaseAmount());
                    detail.setSeriousMedicalUnitRatio(new BigDecimal(item.getCompanyRate()));
                    detail.setLargeMedicalIndividualRatio(new BigDecimal(item.getPersonalRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP7.getCode())){
                    //残保金
                    detail.setUnitDisabilityInsuranceBase(item.getBaseAmount());
                    detail.setUnitDisabilityInsuranceRatio(new BigDecimal(item.getCompanyRate()));
                }else if (ObjUtil.equals(item.getCoverageType(), HrmSocialSecurityCoverageTypeEnum.TYEP8.getCode())){
                    //长期照护险
                    detail.setLongTermPassportInsuranceBase(item.getBaseAmount());
                    detail.setLongTermPassportInsuranceRatio(new BigDecimal(item.getPersonalRate()));
                }
            }
        }

        return detail;
    }

}
